import { LayerManager } from "../../../manager/LayerManager";
import { TweenLite } from "../../../../../com/greensock/TweenLite";
import { TAchievementDetatil } from "../../../../../Message/Db/Tables/TAchievementDetatil";
import { AchievementConfig } from "../../../resource/AchievementConfig";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { Language } from "../../../../../extend/language/Language";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GameController } from "../../../mvc/GameController";
import { GameManager } from "../../../manager/GameManager";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { FontUtil } from "../../../../common/font/FontUtil";
import { AchievementGetBonusButton } from "../item/AchievementGetBonusButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class AchievementFinishedWin
    
    export  class AchievementFinishedWin /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._timerId = -1;
            this._isTweening = false;
            this.x = 600;
            this.y = 230;
            this.init();
            return;
        }

        public get isTweening(): Boolean
        {
            return this._isTweening;
        }

        public init(): void
        {
            this.initView();
            LayerManager.topLayer.addChild(this);
            this.x = 450;
            this.y = 400;
            this._btnGet.addEventListener(flash.events.MouseEvent.CLICK, this.clickGetBonusHandler);
            this._txtOpen.addEventListener(flash.events.MouseEvent.CLICK, this.clickOpenHandler);
            return;
        }

        public clearTimer(): void
        {
            if (this._timerId == -1) 
            {
                return;
            }
            flash.utils.clearTimeout(this._timerId);
            return;
        }

        public show(arg1: number=2, arg2: Function=null): void
        {
            var showSecondes: number=2;
            var callback: Function=null;
            var hideMe: Function;

            var loc1;
            hideMe = null;
            showSecondes = arg1;
            callback = arg2;
            hideMe = (): void
            {
                _isTweening = false;
                _timerId = -1;
                hide();
                return;
            }
            this._callback = callback;
            this.visible = true;
            this._timerId = flash.utils.setTimeout(hideMe, showSecondes * 1000);
            this._isTweening = true;
            this.x = 1100;
            this.y = 40;
            var loc2;
            this.scaleY = loc2 = 0.1;
            this.scaleX = loc2;
            TweenLite.to(this, 0.5, {"x": 450, "y": 320, "scaleX": 1, "scaleY": 1, "onComplete": this.shake});
            return;
        }

        public hide(): void
        {
            this.visible = false;
            if (this._callback != null) 
            {
                this._callback.apply(null, [null]);
                this._callback = null;
            }
            return;
        }

        public updateView(arg1: TAchievementDetatil): void
        {
            var loc2=null;
            this._data = arg1;
            if (this._data == null) 
            {
                return;
            }
            while (this._icon.numChildren > 0) 
            {
                this._icon.removeChildAt(0);
            }
            var loc1=AchievementConfig.instance.getAchievementType(this._data.category, this._data.type);
            if (loc1 == null) 
            {
                return;
            }
            LoaderManager.instance.load(loc1.icon.toString() + ".jpg", this.onIconLoaded);
            loc2 = loc1.name + "(" + this._data.idx.toString() + ")";
            this._txtName.htmlText = loc2;
            loc2 = this._data.descStr;
            this._txtDesc.htmlText = loc2;
            loc2 = Language.getStringByParam(80057, this._data.point);
            this._txtAchievement2.htmlText = loc2;
            loc2 = Language.getStringByParam(80058, this._data.bindCoin);
            this._txtBCoin.htmlText = loc2;
            this._txtAchievement.text = this._data.point.toString();
            return;
        }

        /* internal  */onIconLoaded(arg1: ImageInfo): void
        {
            var loc1=null;
            loc1 = new Object /* flash.display.Bitmap */();
            loc1.bitmapData = arg1.bitmapData;
            this._icon.addChild(loc1);
            return;
        }

        /* internal  */clickGetBonusHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementGetMinorBonus, this._data.code));
            return;
        }

        public shake(arg1: number=0.1): void
        {
            return;
        }

        /* internal  */clickOpenHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            if (GameController.achievement.view.isHide) 
            {
                GameManager.instance.popupView(GameController.achievement.view);
            }
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=null;
            var loc2=null;
            var loc4=null;
            loc1 = new Object /* flash.display.Bitmap */();
            this.addChild(loc1);
            loc1.bitmapData = GlobalClass.getBitmapData(ImagesConst.AchievementDiban);
            loc1 = GlobalClass.getBitmap(ImagesConst.AchievementIconBgBig);
            loc1.x = 42;
            loc1.y = 147;
            this.addChild(loc1);
            this._icon = new Object /* flash.display.Sprite */();
            this._icon.x = 48;
            this._icon.y = 153;
            this.addChild(this._icon);
            this._txtName = ObjCreate.createGTextField("", 153, 120, 220, 24, this);
            loc2 = this._txtName.defaultTextFormat;
            loc2.size = 22;
            loc2.bold = true;
            loc2.font = FontUtil.xingkaiName;
            loc2.color = 16776195;
            this._txtName.defaultTextFormat = loc2;
            this._txtDesc = ObjCreate.createGTextField("", 127, 162, 160, 40, this);
            loc2 = this._txtDesc.defaultTextFormat;
            loc2.color = 65304;
            this._txtDesc.multiline = true;
            this._txtDesc.wordWrap = true;
            this._txtDesc.defaultTextFormat = loc2;
            this._txtAchievement2 = ObjCreate.createGTextField("", 127, 194, 120, 20, this);
            this._txtBCoin = ObjCreate.createGTextField("", 208, 194, 120, 20, this);
            this._txtOpen = ObjCreate.createGTextField("", 337, 194, 120, 20, this);
            loc2 = this._txtOpen.defaultTextFormat;
            loc2.underline = true;
            loc2.color = 16776192;
            this._txtOpen.defaultTextFormat = loc2;
            this._txtOpen.text = Language.getString(80065);
            this._btnGet = new AchievementGetBonusButton(341, 155, this);
            this._btnGet.label = Language.getString(80061);
            var loc3=ObjCreate.createGButton("", 396, 108, 19, 19, this, "CloseButton");
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.clickCloseHandler);
            (loc4 = new Object /* flash.display.Sprite */()).x = 300;
            loc4.y = 165;
            this.addChild(loc4);
            loc1 = new Object /* flash.display.Bitmap */();
            loc1.bitmapData = GlobalClass.getBitmapData(ImagesConst.AchievementChengjiudian);
            loc1.y = 24;
            loc1.x = -5;
            loc4.addChild(loc1);
            this._chengjiudianIcon = new Object /* flash.display.Bitmap */();
            this._chengjiudianIcon.bitmapData = GlobalClass.getBitmap(ImagesConst.StrengthenEnable).bitmapData;
            this._chengjiudianIcon.x = 0;
            this._chengjiudianIcon.y = 0;
            loc4.addChild(this._chengjiudianIcon);
            this._txtAchievement = ObjCreate.createGTextField("", -14, 7, 54, 26, loc4);
            loc2 = this._txtAchievement.defaultTextFormat;
            loc2.align = flash.text.TextFormatAlign.CENTER;
            loc2.color = 15452226;
            this._txtAchievement.defaultTextFormat = loc2;
            return;
        }

        /* internal  */clickCloseHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal */ /* var */_icon: Object /* flash.display.Sprite */;

        /* internal */ /* var */_txtName: GTextFiled;

        /* internal */ /* var */_txtDesc: GTextFiled;

        /* internal */ /* var */_txtAchievement2: GTextFiled;

        /* internal */ /* var */_txtAchievement: GTextFiled;

        /* internal */ /* var */_chengjiudianIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_txtBCoin: GTextFiled;

        /* internal */ /* var */_txtOpen: GTextFiled;

        /* internal */ /* var */_btnGet: AchievementGetBonusButton;

        /* internal */ /* var */_isTweening: Boolean;

        /* internal */ /* var */_timerId: int;

        /* internal */ /* var */_data: TAchievementDetatil;

        /* internal */ /* var */_callback: Function;
    }
